#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS 1
#endif
/*
http://ybt.ssoier.cn:8088/problem_show.php?pid=1285
*/
#include<iostream>
#include<vector>
using namespace std;
int n; 
vector<int>dp,a;
int ans;

int main() {
	cin>>n;
	dp.resize(n+1,0);
	a=dp;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		dp[i]=a[i];
	}
	for(int i=2;i<=n;i++)
		for(int j=1;j<i;j++){
			if(a[i]>a[j])
				dp[i]=max(dp[i],dp[j]+a[i]);
			ans=max(dp[i],ans);
		}
	
	cout<<ans<<endl;
	return 0;
}
